package default01;

import javax.swing.*;

/**
 * @TODO
 * @Author xu
 * 2025/3/15
 */
public class LoginService {
    private String correctUsername = "admin"; // 正确的账户名
    private String correctPassword = "password"; // 正确的密码

    // 登录方法
    public void login(String username, String password) throws LoginException {
        // 1. 账户或密码不能为空
        if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
            throw new LoginException("账户或密码不能为空");
        }

        // 2. 账户与密码不匹配
        if (!username.equals(correctUsername) || !password.equals(correctPassword)) {
            throw new LoginException("账户与密码不匹配");
        }

        // 登录成功
        JOptionPane.showMessageDialog(null, "登录成功！");
    }
}
